package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.IUserDao;
import com.dao.UserDaoImpl;
import com.entity.User;

public class FindAllUsers extends HttpServlet {
	private IUserDao userDao  = new UserDaoImpl();
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("FindAllUsersServlet's doGet()...");
		
		List<User> users = userDao.findAllUsers();
		
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		
		HttpSession session = req.getSession();
		session.setAttribute("users", users);
		req.getRequestDispatcher("findallusers.jsp").forward(req, resp);
		
	}

	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("FindAllServlet's doPost()...");
		//����û��������
		String name = req.getParameter("name");
		String password = req.getParameter("password");
		List<User> users = userDao.findAllUsers();
		System.out.println(users);
		if(users!=null){
			//req.getRequestDispatcher("/success.html").forward(req, resp);
		}else{
			//req.getRequestDispatcher("/login.html").forward(req, resp);
		}
	}
}
